import * as types from '../mutation-types'

const state={
  dateParams:[],
  datePick:{}
};
const getters = {
  dateParams:state=>state.dateParams,
  datePick:state=>state.datePick,
};
const mutations={
  [types.SET_DATEPARAMS](state, data){
    if(state.dateParams<1){
      state.dateParams.push(data)
    }else{
      for (var i in state.dateParams) {
        let item = state.dateParams[i];
        for(let j in item){
          if(!data[j]){
            state.dateParams.push(data)
          }else{
            state.dateParams[i][j] = data[j]
          }
        }
      }
    }
  },
  [types.SET_DATEPICK](state, data){
    for(let i in data){
      if(data[i]){
        state.datePick=Object.assign(state.datePick,data);
      }else{
        delete state.datePick[i]
      }
    }
    console.log("state.datePick",state.datePick);
  },
  [types.CLEAR_QUERYPARAMS](state){
    state.dateParams=[]
  },
  [types.CLEAR_DATAPICK](state){
    state.datePick={}
  }
};
const actions={
  setDateParams({commit},value){
    commit("SET_DATEPARAMS",value)
  },
  clearQueryParams({commit}){
    commit("CLEAR_QUERYPARAMS")
  },
  //initDateParams({ commit, state ,data }){
  //  var promise = new Promise(function (resolve, reject) {
  //    commit(types.SET_DATEPARAMS, promise);
  //    resolve(data);
  //  }
  //  return promise;
  //}
};

export default {
  state,
  getters,
  actions,
  mutations
}
